package oims;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import db.DbAccess;
import db.Record;

public class OrderRecordItem extends DbAccess<OrderRecordItem> implements Record<OrderRecordItem> {

	private int orderId;
	private String product;
	private int price;
	private int quantity;

	/* (非 Javadoc)
	 * @see db.Record#find(int)
	 */
	@Override
	public Record<OrderRecordItem> find(int id) {
		return find_by_id("order_items", id);
	}

	/* (非 Javadoc)
	 * @see db.Record#add()
	 */
	@Override
	public int add() {
	//	return add("order_items", RecordToMap());
		return 0;
	}

	/* (非 Javadoc)
	 * @see db.Record#remove(int)
	 */
	@Override
	public int remove(int id) {
		return remove_by_id("order_items", id);
	}

	/* (非 Javadoc)
	 * @see db.Record#update()
	 */
	@Override
	public int update() {
		return update("order_items", RecordToMap());
	}

	/* (非 Javadoc)
	 * @see db.DbAccess#ResultSetToRecord(java.sql.ResultSet)
	 */
	@Override
	protected Record<OrderRecordItem> ResultSetToRecord(ResultSet rs) {
		try {
			super.setId(rs.getInt("id"));
			this.setOrderId( rs.getInt("orderId"));
			this.setProduct( rs.getString("product"));
			this.setPrice( rs.getInt("price"));
			this.setQuantity(rs.getInt("quantity"));
		}
		catch (SQLException e) {
			e.printStackTrace();
		}
		return this;
	}

	/* (非 Javadoc)
	 * @see db.DbAccess#RecordToMap()
	 */
	@Override
	protected Map<String, String> RecordToMap() {
		Map<String, String> map = new HashMap<String, String>();

		map.put("id", String.valueOf(super.getId()));
		map.put("orderId", String.valueOf(orderId));
		if (this.product != null) map.put("product", this.product);
		map.put("price", String.valueOf(price));
		map.put("quantity", String.valueOf(quantity));

		return map;
	}

	/**
	 * @return product
	 */
	public String getProduct() {
		return product;
	}

	/**
	 * @param product セットする product
	 */
	public void setProduct(String product) {
		this.product = product;
	}

	/**
	 * @return orderId
	 */
	public int getOrderId() {
		return orderId;
	}

	/**
	 * @param orderId セットする orderId
	 */
	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	/**
	 * @return price
	 */
	public int getPrice() {
		return price;
	}

	/**
	 * @param price セットする price
	 */
	public void setPrice(int price) {
		this.price = price;
	}

	/**
	 * @return quantity
	 */
	public int getQuantity() {
		return quantity;
	}

	/**
	 * @param quantity セットする quantity
	 */
	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

}
